#!/usr/bin/env gosh

;; Generate names
(import (scheme base)
        (scheme read)
        (scheme write)
        (scheme char)
        (srfi 27)
        (srfi 28))

(random-source-randomize! default-random-source)

(define (list-random l)
  (list-ref l (random-integer (length l))))

(define (printf . l)
  (display (apply format l)))

;; To capitalize the first letter
(define (list-set l i v)
  (if (= i 0)
      (cons v (cdr l))
      (cons (car l) (list-set (cdr l) (- i 1) v))))

(define (string-set s i v)
  (list->string (list-set (string->list s) i v)))

(define (capitalize-first s)
  (string-set s 0 (char-upcase (string-ref s 0))))

(define name-parts
  '("ab" "abo" "ad" "adi" "af" "afi" "ag" "agu" "am" "ame" "an" "ao" 
    "ap" "apr" "ar" "as" "at" "av" "aw" "awe" "ax" "ay" "az" "be" "bef" 
    "ber" "beg" "bed" "ban" "bar" "ba" "bas" "bin" "bod" "ca" "co" 
    "cur" "can" "da" "do" "du" "dar" "dus" "dan" "duk" "das" "daz" 
    "dash" "eg" "el" "es" "ez" "ex" "fu" "fa" "fo" "ga" "go" "gus" 
    "gore" "gash" "gane" "gobe" "anor" "aber" "aled" "azid" "donus" 
    "dalor" "dack" "ack" "abus" "roth" "shush" "shuth" "so" "sad" "sod" 
    "sun" "spar" "mon" "mal" "mog" "for" "gog" "abb" "zud" "zod" "zun" 
    "sas" "leb" "lib" "lor" "leg" "la" "gage" "hohe" "hoth" "vint" 
    "went" "weld" "sard" "dangt" "agt" "vive" "surge" "sang" "hunt" 
    "saunt" "sent" "send" "store" "leap" "treap" "treed" "tree" "list" 
    "link" "vect" "pair" "strin" "pink" "red" "white" "blue" "green" 
    "shy" "loud" "proud" "anger" "loth" "ben" "ten" "sar" "sharp" 
    "reck" "ralph" "phin" "phor" "phas" "phase" "mount" "rush" "geor" 
    "wash" "aber" "ham" "coin" "qua" "qui" "que" "reap" "blas" "the" 
    "pen" "is" "mite" "ear" "than" "sord" "worm" "ur" "god" "dog" "cat" 
    "tak" "vet" "blak" "lob" "lab" "mom" "mon" "nom" "nor" "ron"
    "pie" "ere" "joe" "seph" "hon" "rich" "ard" "dide" "rot"
    "mat" "thew" "mark" "luke" "jon" "sai" "mone" "zeb" "ra" "do" "da"
    "do" "re" "me" "so" "ti" "gone" "err" "cha" "pand" "lion"))

(define (random-single-name)
  ((list-random
    (list
     (lambda ()
       (format "~a"
               (capitalize-first (list-random name-parts))))
     (lambda ()
       (format "~a~a"
               (capitalize-first (list-random name-parts))
               (list-random name-parts)))
     (lambda ()
       (format "~a~a~a"
               (capitalize-first (list-random name-parts))
               (list-random name-parts)
               (list-random name-parts)))))))

(define (random-name)
  (string-append
   (random-single-name)
   " "
   (random-single-name)))

